package com.cea.papyrus.diagram.sequence.ui.validators;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Expression;
import org.eclipse.uml2.uml.InstanceValue;
import org.eclipse.uml2.uml.LiteralBoolean;
import org.eclipse.uml2.uml.LiteralInteger;
import org.eclipse.uml2.uml.LiteralNull;
import org.eclipse.uml2.uml.LiteralString;
import org.eclipse.uml2.uml.LiteralUnlimitedNatural;

import com.cea.papyrus.core.presentation.UMLDecoratedLabelProvider;

public class UMLLabelProvider extends LabelProvider {

	private UMLDecoratedLabelProvider provider;
	
	public UMLLabelProvider(UMLDecoratedLabelProvider provider) {
		super();
		this.provider = provider;
	}

	@Override
	public Image getImage(Object element) {
		return provider.getImage(element);
	}

	@Override
	public String getText(Object element) {
		if (element instanceof Expression) {
			return ((Expression) element).getSymbol();
			
		} else if (element instanceof InstanceValue) {
			return ((InstanceValue) element).getInstance().getLabel();
			
		} else if (element instanceof LiteralInteger) {
			int value = ((LiteralInteger) element).getValue();
			return new Integer(value).toString();
			
		} else if (element instanceof LiteralString) {
			return ((LiteralString) element).getValue();
			
		} else if (element instanceof LiteralUnlimitedNatural) {
			int value = ((LiteralUnlimitedNatural) element).getValue();
			if (value == -1) {
				return "*";
			} else {
				return new Integer(value).toString();
			}
			
		} else if (element instanceof LiteralNull) {
			return "null (LiteralNull)";
			
		} else if (element instanceof LiteralBoolean) {
			boolean value = ((LiteralBoolean) element).booleanValue();
			if (value) {
				return "true";
			} else {
				return "false";
			}
			
		} else {
			return provider.getText(element);
		}			
	}

}
